package com.ruoyi.web.controller.front;

import java.util.List;

import com.ruoyi.business.domain.BusinessClock;
import com.ruoyi.business.domain.BusinessLeave;
import com.ruoyi.business.domain.StatisticsDept;
import com.ruoyi.business.domain.StatisticsLeaveEveryday;
import com.ruoyi.business.service.IBusinessClockService;
import com.ruoyi.business.service.IBusinessLeaveService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.front.service.IFrontStatisticsService;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.front.service.IFrontLeaveService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/front/statistics")
public class FrontStatisticsController extends BaseController
{
    @Autowired
    private IFrontStatisticsService frontStatisticsService;

    @Autowired
    private IBusinessLeaveService businessLeaveService;


    @Autowired
    private ISysUserService userService;

    @Autowired
    private IBusinessClockService businessClockService;

    @Autowired
    private SysUserMapper userMapper;


    /**
     * 查询各部门员工人数
     */
    @GetMapping("/dept")
    public List<StatisticsDept> list()
    {
        List<StatisticsDept> dept = frontStatisticsService.selectStatisticsDeptList();
        for (StatisticsDept deptt : dept) {
            System.out.println("部门名称: " + deptt.getDepartmentName() + ", 部门人数: " + deptt.getEmployeeCount());
        }


        return dept;
    }



    /**
     * // 查询今年与上一年的每日请假人数
     */
    @GetMapping("/leaveEveryday")
    public List<StatisticsLeaveEveryday> getLeaveData(@RequestParam("startYear") int startYear) {
        List<StatisticsLeaveEveryday> leaveDataList = frontStatisticsService.selectLeaveData(startYear);

        // 打印数据（可选）
        leaveDataList.forEach(leaveData -> {
            System.out.println("日期: " + leaveData.getDate() + ", 请假人数: " + leaveData.getCount());
        });

        return leaveDataList;
    }

    /**
     * 查询请假管理列表
     */
    @GetMapping("/leaveList")
    public TableDataInfo list(BusinessLeave businessLeave)
    {
        startPage();
        List<BusinessLeave> list = businessLeaveService.selectBusinessLeaveList(businessLeave);
        return getDataTable(list);
    }

    /**
     * 获取用户列表
     */
    @GetMapping("/userList")
    public TableDataInfo list(SysUser user)
    {
        startPage();
        List<SysUser> list = userMapper.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 查询考勤列表
     */
    @GetMapping("/clockList")
    public TableDataInfo list(BusinessClock businessClock)
    {
        startPage();
        List<BusinessClock> list = businessClockService.selectBusinessClockList(businessClock);
        return getDataTable(list);
    }
}
